
#include "../include/bufferTeclado.h"

/* buffer circular de teclado */
#define		MAX_BUFFER	2000

static char buffer[MAX_BUFFER];
static int head =0;
static int tail = 0;

int
BufferTecladoFull(void)
{
	return ((tail + 1) % (MAX_BUFFER) == head);
}

int
BufferTecladoEmpty(void)
{
	return (head == tail);
}

int
InsertarTecladoKey(char c)  {
	if (BufferTecladoFull()) {
		return -1;
	}	
	buffer[tail] = c;
	tail = (tail + 1) % (MAX_BUFFER);
	
	
	return c;
}

int
GetTecladoKey(void)  {
	char c = 0;
	if (!BufferTecladoEmpty())
	{
		c = buffer[head];
		head = (head + 1) % (MAX_BUFFER);
	}
	return c;
}
